package com.simple.datax.dao.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.simple.base.dao.BaseDAO;
import com.simple.datax.dao.IDataxNodeChannelDAO;
import com.simple.datax.vo.DataxNodeChannelVO;
import com.simple.util.common.StringUtil;
import com.simple.util.common.Utils;
import com.simple.util.object.PageInfoBean;

@Repository("dataxNodeChannelDAO")
public class DataxNodeChannelDAOImpl extends BaseDAO implements
		IDataxNodeChannelDAO {

	@Override
	public DataxNodeChannelVO findByNode(String fcNode) {
		return (DataxNodeChannelVO)super.get(DataxNodeChannelVO.class, fcNode);
	}

	@Override
	public void saveOrUpdate(DataxNodeChannelVO dataxNodeChannelVO) {
		super.saveOrUpdate(dataxNodeChannelVO);

	}

	@Override
	public List<DataxNodeChannelVO> findAll() {
		return super.query(DataxNodeChannelVO.class);
	}

	@Override
	public void delete(DataxNodeChannelVO dataxNodeChannelVO) {
		super.delete(dataxNodeChannelVO);

	}

	@SuppressWarnings("unchecked")
	@Override
	public List<DataxNodeChannelVO> findDataxNodeChannelVOByPage(final PageInfoBean pageInfoBean, final String fcNode, final String fcCommunSendType, final String fcCommunRecvType, final String fiFlag) {
		final Map<String, Object> paramMap = new LinkedHashMap<String,Object>();
        final StringBuffer sb = new StringBuffer(300);
        
        sb.append( "select  d from DataxNodeChannelVO d where 1>0 " );
        if(!StringUtil.isNull(fcNode)){
            sb.append( " and d.fcNode like :fcNode" );
            paramMap.put("fcNode", "%" + fcNode + "%");
        }
        if(!StringUtil.isNull(fcCommunSendType)){
            sb.append( " and d.fcCommunSendType=:fcCommunSendType" );
            paramMap.put("fcCommunSendType", fcCommunSendType);
        }
        if(!StringUtil.isNull(fcCommunRecvType)){
            sb.append( " and d.fcCommunRecvType=:fcCommunRecvType" );
            paramMap.put("fcCommunRecvType", fcCommunRecvType);
        }
        if(!StringUtil.isNull(fiFlag)){
        	sb.append( " and d.fiFlag=:fiFlag" );
        	paramMap.put("fiFlag", Utils.parseInt(fiFlag));
        }
        sb.append( " order by d.fcNode desc" );
        return (List<DataxNodeChannelVO>) super.queryListByPage("d.fcNode", sb.toString(), paramMap, pageInfoBean);
		
	}
}
